/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bsc.war.populate;

import bsc.ejb.entity.Pointer;
import bsc.ejb.entity.ScoreCard;
import bsc.ejb.entity.Settings;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.service.ScoreCardUtils;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author luisZavaleta
 */
public class RestoreDB extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");


        //Se crea un FrameWork
        try {

            List<ScoreCard> scoreCards = delegate.findScoreCard();

            for (ScoreCard scoreCard : scoreCards) {
                if (scoreCard instanceof Pointer) {
                    //Find the cuts of the pointer
                    /*List<DimensionalCut> dimensionalCuts = delegate.findDimensionalCut((Pointer) scoreCard);
                    List<DimensionalCut> rootDimensionalCuts = new ArrayList<DimensionalCut>();

                    //Members of the cut
                    Map<DimensionalCut, List<DimensionMember>> cutMembers = new HashMap<DimensionalCut, List<DimensionMember>>();
                    //Members of members boolean
                    Map<DimensionalCut, Map<DimensionMember, Boolean>> cutMembersSons = new HashMap<DimensionalCut, Map<DimensionMember, Boolean>>();

                    //Members Strng of the Cut
                    Map<DimensionalCut, String> cutMembersString = new HashMap<DimensionalCut, String>();

                    for (DimensionalCut dimensionalCut : dimensionalCuts) {
                        List<DimensionMember> dimensionMembers = delegate.findDimensionMember(dimensionalCut);

                        if (!ScoreCardUtils.reviewRoot(dimensionMembers)) {
                            dimensionalCut.setType(DimensionalCut.Type.STANDARD);
                            delegate.updateDimensionalCut(dimensionalCut);
                        }
                    }*/

                    String dateString = "01/01/2009";
                    Date date = ScoreCardUtils.generateDate(dateString);
                    Settings settings = scoreCard.getSettings();
                    settings.setRegisterDate(date);

                    delegate.updateSettings(settings);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }





        return new ModelAndView("advancePopulate");
    }
}
